package jdbc;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.Scanner;

public class JDBCDemo10 {
    public static void main(String[] args) {

        try (Connection connection = DBUtil.getConnection()){
            Scanner scanner = new Scanner(System.in);
            System.out.println("请输入id");
            String id = scanner.nextLine();
            System.out.println("请输入修改的用户名");
            String username = scanner.nextLine();
            System.out.println("请输入修改后的密码");
            String password = scanner.nextLine();
            System.out.println("请输入修改后的昵称");
            String nickname = scanner.nextLine();
            String sql = "UPDATE userinfo SET username = ? , password = ? , nickname = ?" +
                    "WHERE id = ?";
            PreparedStatement ps = connection.prepareStatement(sql);
            ps.setString(4,id);
            ps.setString(1,username);
            ps.setString(2,password);
            ps.setString(3,nickname);
            int i = ps.executeUpdate();
            System.out.println(i>0?"修改成功":"修改失败");
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
